﻿using ExpressManagement.Areas.BackSys.Hubs;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;


namespace ExpressManagement.Areas.BackSys.ServiceTools
{
    public class SignalRSender
    {
        Thread m_thread = null;
        private static ChatHub signalR = null;
        public SignalRSender()
        {
            if(signalR==null)
            signalR = new ChatHub();
          
        }

        #region 发送消息
        /// <summary>
        /// 以个人名义向所有客户端发送消息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendToAll(string message)
        {
            //string cid = GetConnectionId();
            await signalR.SendToAll(message);
        }

        /// <summary>
        /// 以系统名义向所有客户端发送消息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendSysToAll(string message) => await signalR.SendSysToAll(message);


        /// <summary>
        /// 发送消息给指定用户(个人)
        /// </summary>
        /// <param name="id"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendToOneByUserId(int userId, string message)
        {
            //string cid = GetConnectionId();
            //await Clients.Client(id).ReceiveMessage(new(cid, _connections[cid], message));
            await signalR.SendToOneByUserId(userId, message);
        }



        /// <summary>
        /// 发送消息给指定用户(系统)
        /// </summary>
        /// <param name="id"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendSysToOneByUserId(int userId, string message) => await signalR.SendSysToOneByUserId(userId, message);

        /// <summary>
        /// 发送群组消息(个人)
        /// </summary>
        /// <param name="group"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendToGroup(string group, string message)
        {
            //string cid = GetConnectionId();
            await signalR.SendToGroup(group, message);
        }


        /// <summary>
        /// 发送群组消息(系统)
        /// </summary>
        /// <param name="group"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendSysToGroup(string group, string message) => await signalR.SendSysToGroup(group, message);

        #endregion




    }

}